<script>
	function submitForm(buttonId) {
		document.getElementById("showtime_id").value = buttonId;
	}
</script>

<div class ="row">
	
	<div class="span4">
		<ul class="thumbnails">
			<li class="span4">
				<div class="thumbnail">
					<!--<img data-src="" alt="">-->
					<h3>Schedules</h3>
					<p>Choose a schedule and click on buy to start your purchase.</p>
				</div>
			</li> 
		</ul>
	</div>
	
	<form class="form-inline" action="choose_seat" method="post">
		<div class="span8">
			<table class="table table-hover" style="width: 100%">
				<?php
					if(isset($timeSelection) && $timeSelection->num_rows() > 0) {
						$result = $timeSelection->result_array();
						echo "<caption></caption>";
						echo "<thead><tr><th>Title</th><th>Theater</th><th>Date</th><th>Availability</th><th>Price</th></tr></thead>";
						echo "<tbody>";
						foreach($result as $row) {
							echo "<tr>";
							echo "<td>" . $row['title'] . "</td>";
							echo "<td>" . $row['name'] . " - " . $row['address'] .  "</td>";
							echo "<td>" . $row['date'] . " - " . $row['time'] .  "</td>";
							echo "<td>" . $row['available'] . "</td>";
							echo "<td>$6.00</td>";
							echo "<td><button id=\"". $row['id'] ."\" type=\"submit\" onClick=\"submitForm(this.id)\">Buy</button></td>";
							echo "</tr>";
						}
						echo "</tbody>";
						echo '<input type="hidden" name="showtimeId" id="showtime_id" value="" />';
					} else if($timeSelection->num_rows() <= 0) {
						echo "<p>No movies matched your selection.</p>";
					}
				?>
			</table>
		</div>
	</form>

</div> <!-- closing row -->